/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.common.constant.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 审核状态
 *
 * @author duanlikao
 * @created 2020/12/14
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum ExamineStatusEnum {

    EXAMINE_STATUS_TOSUBMITTED("0", "待提交"),
    EXAMINE_STATUS_TOREVIEWED("1", "待审核"),
    EXAMINE_STATUS_APPROVED("2", "审核通过"),
    EXAMINE_STATUS_AUDIT_FAILURE("3", "审核失败");

    private  String code;
    private  String msg;

    private static Map <String, ExamineStatusEnum> codeMap = Maps.newHashMap();

    public String getCode() {
        return this.code;
    }

    public String getDesc() {
        return this.msg;
    }

    public static String getMsg(String code) {
        return codeMap.containsKey(code) ? codeMap.get(code).getDesc() : StringUtils.EMPTY;
    }

    public static boolean isValid(String code) {
        return codeMap.containsKey(code);
    }

    static {
        for (ExamineStatusEnum status : ExamineStatusEnum.values()) {
            codeMap.put(status.getCode(), status);
        }
    }

    public static ExamineStatusEnum getExamineStatusEnumByVal(String code) {
        return Arrays.stream(ExamineStatusEnum.values())
                .collect(Collectors.toMap(ExamineStatusEnum::getCode, value -> value, (k1, k2) -> k2)).get(code);
    }

}